Skip to content

Find rfl::Short and rfl::Positional through other wrappers in rfl::cli - #790

Draft
clockblocker wants to merge 2 commits into
munich-data-engineering:mainfrom
clockblocker:cli-wrapped-short-positional-main
Draft

clockblocker wants to merge 2 commits into
munich-data-engineering:mainfrom
clockblocker:cli-wrapped-short-positional-main

Conversation

@clockblocker

Copy link
Copy Markdown
Contributor

Summary

Finds rfl::Short and rfl::Positional through rfl::DefaultVal, std::optional, rfl::Description, rfl::Rename, and rfl::Deprecated in any nesting order in rfl::cli.

Stacked on #789 (only the top commit belongs to this PR; will rebase onto main and mark ready once #789 merges).

Example

struct Config {
  rfl::Description<"Log file", rfl::Short<"l", std::optional<std::string>>> log;
  rfl::Description<"Dry run", rfl::Short<"n", bool>> dry_run;
  rfl::DefaultVal<rfl::Positional<std::string>> first = std::string("1");
  std::optional<rfl::Positional<std::string>> second;
};

// ./app -l app.log -n a.txt b.txt
// Before: Unknown short argument: -l  (and Too many positional arguments)
// After:  log="app.log", dry_run=true, first="a.txt", second="b.txt"

Key details

  • Every wrapped Short and Positional behaves identically to a bare one (flags, value options, declaration-order positionals, duplicate-short checks).
  • Combining two Short/Positional wrappers on the same field (e.g. Short<"o", Description<"...", Positional<T>>>) is now a compile-time error instead of silently ignoring the inner one.
  • rfl::Rename still applies only as the outermost wrapper.
  • Docs updated in cli.md ("Combining wrappers").

AI-authored.

clockblocker and others added 2 commits November 21, 2026 10:03
rfl::cli decided after parsing which short options were bool flags, so a
token a flag had taken went back to the positional arguments ahead of the
others: `x -v y` gave a=y, b=x.

rfl::cli::read now derives an internal option table from the struct
(rfl::cli::internal::make_options, options.hpp) and parses with it, so it
knows while parsing what each short option does with the next token:

- Positional arguments keep their command-line order: `x -v y` gives
  a=x, b=y.
- Short<"q", std::optional<bool>> and Short<"q", DefaultVal<bool>> are
  flags: `-q in.txt` leaves in.txt positional.
- `-o` without a value fails with "Missing value for option '-o'.", and
  `-v=x` on a bool short flag fails to cast x.
- A root rfl::NamedTuple whose field names the processors change reads
  its Short and Positional fields.
- "Duplicate short name" is reported before errors in the arguments.

The public parse_argv and resolve_args keep working without the table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfl::cli only recognized rfl::Short and rfl::Positional as the outermost
wrapper of a field, so `rfl::Description<"...", rfl::Short<"o", T>>` had
no `-o` and `std::optional<rfl::Positional<T>>` was not positional.

The option table now finds them through DefaultVal, std::optional,
Description, Rename and Deprecated, in any order. Every Short and
Positional counts wherever it sits: positional fields take bare arguments
in declaration order, two fields with the same short name are an error,
and a field with more than one Short or Positional does not compile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant